package com.aoxin.util;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateWay {
	public static String GetTime(){
	    String temp_str="";     
	    Date dt = new Date();     
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");     
	    temp_str=sdf.format(dt);  
	    return temp_str; 
	}
	
	public static String GetNextTime(Integer day){
		Date date=new Date();//取时间
		Calendar calendar = new GregorianCalendar();
	    calendar.setTime(date);
	    calendar.add(calendar.DATE,day);//把日期往后增加一天.整数往后推,负数往前移动
	    date=calendar.getTime(); //这个时间就是日期往后推一天的结果 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = formatter.format(date);
		return dateString;
	}
	
	public static String GetNextTimeAll(Integer day){
		Date date=new Date();//取时间
		Calendar calendar = new GregorianCalendar();
	    calendar.setTime(date);
	    calendar.add(calendar.DATE,day);//把日期往后增加一天.整数往后推,负数往前移动
	    date=calendar.getTime(); //这个时间就是日期往后推一天的结果 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = formatter.format(date);
		return dateString;
	}
	
	public static String GetTimeOther(){
	    String temp_str="";     
	    Date dt = new Date();     
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");     
	    temp_str=sdf.format(dt);  
	    return temp_str; 
	}
	
	public static String GetOrderTime(){
	    String temp_str="";     
	    Date dt = new Date();     
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");     
	    temp_str=sdf.format(dt);  
	    return temp_str; 
	}
	/*
	 * 获取全时间
	 */
	public static String TimeAll(){
	    String temp_str="";     
	    Date dt = new Date();     
	    //最后的aa表示“上午”或“下午”    HH表示24小时制    如果换成hh表示12小时制     
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");     
	    temp_str=sdf.format(dt);  
	    return temp_str; 
	}
	
	
	public static String GetCal(String str,Integer count){
	    // 时间表示格式可以改变，yyyyMMdd需要写例如20160523这种形式的时间
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
	    // 将字符串的日期转为Date类型，ParsePosition(0)表示从第一个字符开始解析
	    Date date = sdf.parse(str, new ParsePosition(0));
	    Calendar calendar = Calendar.getInstance();
	    calendar.setTime(date);
	    // add方法中的第二个参数n中，正数表示该日期后n天，负数表示该日期的前n天
	    calendar.add(Calendar.DATE, count);
	    Date date1 = calendar.getTime();
	    String out = sdf.format(date1);
		return out;
	}
	/**
      * 将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss
      * 
      * @param strDate
      * @return
      */
      public static Date strToDateLong(String strDate) {
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      ParsePosition pos = new ParsePosition(0);
      Date strtodate = formatter.parse(strDate, pos);
      return strtodate;
  }   
      
      public static String addDate(String day, int x){ 
  		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制 
  	  //SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制 
  		Date date = null; 
  		try 
  		{ 
  		date = format.parse(day); 
  		} 
  		catch (Exception ex) 
  		{ 
  		ex.printStackTrace(); 
  		} 
  		if (date == null) return ""; 
  		Calendar cal = Calendar.getInstance(); 
  		cal.setTime(date); 
  		cal.add(Calendar.HOUR_OF_DAY, x);//24小时制 
  		//cal.add(Calendar.HOUR, x);12小时制 
  		date = cal.getTime(); 
  		cal = null; 
  		return format.format(date); 
  } 
      /** 
      
      *@param date是为则默认今天日期、可自行设置“2013-06-03”格式的日期 
       
      *@return  返回1是星期日、2是星期一、3是星期二、4是星期三、5是星期四、6是星期五、7是星期六 
       
      */  
      public static int getDayofweek(String date){  
    	  Calendar cal = Calendar.getInstance();  
    	//   cal.setTime(new Date(System.currentTimeMillis()));  
    	  if (date.equals("")) {  
    	   cal.setTime(new Date(System.currentTimeMillis()));  
    	  }else {  
    	   cal.setTime(new Date(getDateByStr2(date).getTime()));  
    	  }  
    	   return cal.get(Calendar.DAY_OF_WEEK);  
    	 }  
      
      public static Date getDateByStr2(String dd)  
      {  
       
       SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");  
       Date date;  
       try {  
        date = sd.parse(dd);  
       } catch (ParseException e) {  
        date = null;  
        e.printStackTrace();  
       }  
       return date;  
      }  
      
      public static String WeekDay(Integer weekDay){
    	  String week = "";
		   if(weekDay == 1){
			   week = "周天";
		   }else if(weekDay == 7){
			   week = "周六";
		   }else if(weekDay == 6){
			   week = "周五";
		   }else if(weekDay == 5){
			   week = "周四";
		   }else if(weekDay == 4){
			   week = "周三";
		   }else if(weekDay == 3){
			   week = "周二";
		   }else if(weekDay == 2){
			   week = "周一";
		   }
		return week;
      }
      
      public static String WeekDayOther(Integer weekDay){
    	  String week = "";
		   if(weekDay == 1){
			   week = "周一";
		   }else if(weekDay == 7){
			   week = "周日";
		   }else if(weekDay == 6){
			   week = "周六";
		   }else if(weekDay == 5){
			   week = "周五";
		   }else if(weekDay == 4){
			   week = "周四";
		   }else if(weekDay == 3){
			   week = "周三";
		   }else if(weekDay == 2){
			   week = "周二";
		   }
		return week;
      }
      public static String GetToWeekDate(String validatetime,int renewalsdata) throws ParseException {
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          Date now = sdf.parse(validatetime);
          Calendar calendar = Calendar.getInstance();
          calendar.setTime(now);
          calendar.add(Calendar.DATE, renewalsdata);
		  return sdf.format(calendar.getTime());
      }   
      /** 
      
      *@param date是为则默认今天日期、可自行设置“2013-06-03”格式的日期 
       
      *@return  返回1是星期日、2是星期一、3是星期二、4是星期三、5是星期四、6是星期五、7是星期六 
       
      */  
        
}
